package cn.iocoder.yudao.module.member.controller.admin.curriculumVitaeSendRecord;

import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.member.api.studentEducationalExperience.dto.StudentEducationalExperienceRespDTO;
import cn.iocoder.yudao.module.member.convert.studentEducationalExperience.StudentEducationalExperienceConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.curriculumVitaeSendRecord.CurriculumVitaeSendInviteRecordDO;
import cn.iocoder.yudao.module.member.dal.dataobject.curriculumVitaeSendRecord.CurriculumVitaeSendRecordGroupDO;
import cn.iocoder.yudao.module.member.dal.dataobject.studentEducationalExperience.StudentEducationalExperienceDO;
import cn.iocoder.yudao.module.member.service.studentEducationalExperience.StudentEducationalExperienceService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.member.controller.admin.curriculumVitaeSendRecord.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.curriculumVitaeSendRecord.CurriculumVitaeSendRecordDO;
import cn.iocoder.yudao.module.member.convert.curriculumVitaeSendRecord.CurriculumVitaeSendRecordConvert;
import cn.iocoder.yudao.module.member.service.curriculumVitaeSendRecord.CurriculumVitaeSendRecordService;

@Api(tags = "管理后台 -运营端- 简历投递记录")
@RestController
@RequestMapping("/member/curriculum-vitae-send-record")
@Validated
public class CurriculumVitaeSendRecordController {

    @Resource
    private CurriculumVitaeSendRecordService curriculumVitaeSendRecordService;
    @Resource
    private StudentEducationalExperienceService studentEducationalExperienceService;
    @PostMapping("/create")
    @ApiOperation("创建简历投递记录")
    public CommonResult<Long> createCurriculumVitaeSendRecord(@Valid CurriculumVitaeSendRecordCreateReqVO createReqVO) {
        return success(curriculumVitaeSendRecordService.createCurriculumVitaeSendRecord(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新简历投递记录")
    public CommonResult<Boolean> updateCurriculumVitaeSendRecord(@Valid CurriculumVitaeSendRecordUpdateReqVO updateReqVO) {
        curriculumVitaeSendRecordService.updateCurriculumVitaeSendRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除简历投递记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    public CommonResult<Boolean> deleteCurriculumVitaeSendRecord(@RequestParam("id") Long id) {
        curriculumVitaeSendRecordService.deleteCurriculumVitaeSendRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得简历投递记录")
    @TenantIgnore
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    public CommonResult<CurriculumVitaeSendRecordRespVO> getCurriculumVitaeSendRecord(@RequestParam("id") Long id) {
        CurriculumVitaeSendRecordDO curriculumVitaeSendRecord = curriculumVitaeSendRecordService.getCurriculumVitaeSendRecord(id);
        return success(CurriculumVitaeSendRecordConvert.INSTANCE.convert(curriculumVitaeSendRecord));
    }

    @GetMapping("/list")
    @ApiOperation("获得简历投递记录列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    public CommonResult<List<CurriculumVitaeSendRecordRespVO>> getCurriculumVitaeSendRecordList(@RequestParam("ids") Collection<Long> ids) {
        List<CurriculumVitaeSendRecordDO> list = curriculumVitaeSendRecordService.getCurriculumVitaeSendRecordList(ids);
        return success(CurriculumVitaeSendRecordConvert.INSTANCE.convertList(list));
    }

    @PostMapping("/admin/checkResumeFromJob")
    @ApiOperation("获得简历投递记录分页")
    @TenantIgnore
    public CommonResult<PageResult<CurriculumVitaeSendRecordRespVO>> checkResumeFromJob(@Valid @RequestBody CurriculumVitaeSendRecordPageReqVO pageVO) throws Exception{
        pageVO.setRelationType(1);
        PageResult<CurriculumVitaeSendRecordDO> pageResult = curriculumVitaeSendRecordService.getCurriculumVitaeSendRecordPage1(pageVO);
        PageResult<CurriculumVitaeSendRecordRespVO>  curriculumVitaeSendRecordRespVOPageResult=CurriculumVitaeSendRecordConvert.INSTANCE.convertPage(pageResult);

        List<CurriculumVitaeSendRecordRespVO> curriculumVitaeSendRecordRespVOS=curriculumVitaeSendRecordRespVOPageResult.getList();
        for (CurriculumVitaeSendRecordRespVO curriculumVitaeSendRecordRespVO:curriculumVitaeSendRecordRespVOS){
           List<StudentEducationalExperienceDO> studentEducationalExperienceDOS = studentEducationalExperienceService.getStudentEducationalExperienceByStudentId(curriculumVitaeSendRecordRespVO.getResumeId());
           curriculumVitaeSendRecordRespVO.setEducationalExperience(StudentEducationalExperienceConvert.INSTANCE.convertList(studentEducationalExperienceDOS));
        }
        curriculumVitaeSendRecordRespVOPageResult.setList(curriculumVitaeSendRecordRespVOS);
        return success(curriculumVitaeSendRecordRespVOPageResult);
    }

    @PostMapping("/page")
    @ApiOperation("获得简历投递记录分页")
    @TenantIgnore
    public CommonResult<PageResult<CurriculumVitaeSendRecordRespVO>> getCurriculumVitaeSendRecordPage(@Valid @RequestBody CurriculumVitaeSendRecordPageReqVO pageVO) throws Exception{
        PageResult<CurriculumVitaeSendRecordDO> pageResult = curriculumVitaeSendRecordService.getCurriculumVitaeSendRecordPage(pageVO);
        return success(CurriculumVitaeSendRecordConvert.INSTANCE.convertPage(pageResult));
    }



    @GetMapping("/export-excel")
    @ApiOperation("导出简历投递记录 Excel")
    @OperateLog(type = EXPORT)
    public void exportCurriculumVitaeSendRecordExcel(@Valid CurriculumVitaeSendRecordExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<CurriculumVitaeSendRecordDO> list = curriculumVitaeSendRecordService.getCurriculumVitaeSendRecordList(exportReqVO);
        // 导出 Excel
        List<CurriculumVitaeSendRecordExcelVO> datas = CurriculumVitaeSendRecordConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "简历投递记录.xls", "数据", CurriculumVitaeSendRecordExcelVO.class, datas);
    }


    @PostMapping("/admin/checkInfoByJob")
    @ApiOperation("根据职位获得简历投递记录分页")
    @TenantIgnore
    public CommonResult<PageResult<CurriculumVitaeSendRecordGroupRespVO>> checkInfoByJob(@Valid @RequestBody CurriculumVitaeSendRecordGroupPageReqVO pageVO) {
        PageResult<CurriculumVitaeSendRecordGroupDO> pageResult = curriculumVitaeSendRecordService.checkInfoByJob(pageVO);
        return success(CurriculumVitaeSendRecordConvert.INSTANCE.convertPage1(pageResult));
    }

    @PostMapping("/admin/getpageByJob")
    @ApiOperation("各职位投递列表")
    public CommonResult<PageResult<CurriculumVitaeSendRecordRespVO>> getpageByJob(@Valid @RequestBody CurriculumVitaeSendRecordPageReqVO pageVO) {
        PageResult<CurriculumVitaeSendRecordDO> pageResult = curriculumVitaeSendRecordService.getpageByJob(pageVO);
        return success(CurriculumVitaeSendRecordConvert.INSTANCE.convertPage(pageResult));
    }

    @PostMapping("/admin/checkInfoByStudent")
    @ApiOperation("根据学生id获得简历投递记录分页")
    public CommonResult<PageResult<CurriculumVitaeSendRecordInviteRespVO>> getpageByStudent(@Valid @RequestBody CurriculumVitaeSendRecordPageReqVO reqVO) {
        PageResult<CurriculumVitaeSendInviteRecordDO> pageResult = curriculumVitaeSendRecordService.getpageByStudent(reqVO);
        return success(CurriculumVitaeSendRecordConvert.INSTANCE.convertPage3(pageResult));
    }

    @PostMapping("/admin/getOperpageByStudent")
    @ApiOperation("根据学生id获得简历投递记录分页")
    @TenantIgnore
    public CommonResult<PageResult<CurriculumVitaeSendRecordInviteRespVO>> getOperpageByStudent(@Valid @RequestBody CurriculumVitaeSendRecordPageReqVO reqVO) {
        PageResult<CurriculumVitaeSendInviteRecordDO> pageResult = curriculumVitaeSendRecordService.getpageByStudent(reqVO);
        return success(CurriculumVitaeSendRecordConvert.INSTANCE.convertPage3(pageResult));
    }

    @PostMapping("/sendStudentCurriculumVitae")
    @ApiOperation("人才推送")
    @TenantIgnore
    public CommonResult<Long> sendStudentCurriculumVitae(@RequestBody SendStudentCurriculumVitaeReqVO reqVO) {
        return success(curriculumVitaeSendRecordService.sendStudentCurriculumVitae(reqVO.getCompanyId(),reqVO.getStudentCurriculumVitaeId(),reqVO.getJobId(),reqVO.getRemark()));
    }




}
